﻿using Core.SimpleTemp.Common;
using Core.SimpleTemp.Entitys;
using Core.Toolkit.DbInitializer;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace Core.SimpleTemp.Repositories.FX
{
    /// <summary>
    /// 风险
    /// </summary>
    public class FX_DBinit : DbInitializer
    {
        public override void Initialize(DbContext context, WebAppOptions _webAppOptions)
        {

            //风险等级
            context.Set<FX_Grade>().Add(new FX_Grade()
            {
                FXScore = 5,
                FXGrade = "1级",
            });
            context.Set<FX_Grade>().Add(new FX_Grade()
            {
                FXScore = 4,
                FXGrade = "2级",
            });
            var gradeLev3guid = Guid.NewGuid();
            context.Set<FX_Grade>().Add(new FX_Grade()
            {
                Id = gradeLev3guid,
                FXScore = 4,
                FXGrade = "3级",
            });
            //风险类别
            List<FX_FXType> FX_FXTypeList = new List<FX_FXType>();
            for (int i = 0; i < 10; i++)
            {
                
                FX_FXTypeList.Add(new FX_FXType()
                {
                    Id=Guid.NewGuid(),
                    ProductionActivityName = "风险类别名称" + i
                });
            }
            context.Set<FX_FXType>().AddRange(FX_FXTypeList);



            //操作及相关作业活动
            for (int i = 0; i < 20; i++)
            {
                context.Set<FX_OperationAndWork>().Add(new FX_OperationAndWork()
                {
                    ControlRequirement = "控制要求test" + i,
                    
                    HazardousFactor = "危害因素test" + i,
                    JobSteps = "作业步骤test" + i,
                    JobTask = "作业任务test" + i,
                    RequirementsComply = "现场作业行为和活动应遵守的要求test" + i,
                    Risk = "风险test" + i,
                    FXTypeID = FX_FXTypeList[new Random().Next(0, 9)].Id,
                    RiskLevel = gradeLev3guid,//风险等级
                });
            }

            //操作程序
            for (int i = 0; i < 20; i++)
            {
                context.Set<FX_Operation>().Add(new FX_Operation()
                {
                    ControlRequirement = "控制要求test" + i,
                    //FXTypeID = gradeLev3guid,
                    HazardousFactor = "危害因素test" + i,
                    JobSteps = "作业步骤test" + i,
                    JobTask = "作业任务test" + i,
                    Risk = "风险test" + i,
                    FXTypeID = FX_FXTypeList[new Random().Next(0, 9)].Id,
                    RiskLevel = gradeLev3guid,//风险等级
                });
            }


            //作业活动
            for (int i = 0; i < 20; i++)
            {
                context.Set<FX_WorkActivity>().Add(new FX_WorkActivity()
                {
                    ControlRequirement = "控制要求test" + i,
                    //FXTypeID = gradeLev3guid,
                    HazardousFactor = "危害因素test" + i,
                    JobSteps = "作业步骤test" + i,
                    JobTask = "作业任务test" + i,
                    Risk = "风险test" + i,
                    RiskLevel = gradeLev3guid,//风险等级
                });
            }

            //风险_检维修作业活动
            for (int i = 0; i < 20; i++)
            {
                context.Set<FX_CheckRepair>().Add(new FX_CheckRepair()
                {
                    JobModule = "作业模块" + i,//作业模块
                    JobActivity = "作业活动" + i,//作业活动
                    MaintanenceProject = "维修项目" + i,//维修项目
                    Risk = "风险" + i,//风险
                    HazardousFactor = "危害因素" + i,//危害因素
                    ControlRequirement = "控制要求" + i,//控制要求
                    FXTypeID = FX_FXTypeList[new Random().Next(0, 9)].Id,
                    RiskLevel = gradeLev3guid,//风险等级
                });
            }

            //风险_设备设施
            for (int i = 0; i < 20; i++)
            {
                context.Set<FX_Equipment>().Add(new FX_Equipment()
                {
                    Device = "设备" + i,//设备
                    FunctionalPart = "功能部分" + i,//功能部分
                    Sub_functionPart = "子功能部分" + i,//子功能部分
                    B_ComponentName = "部件" + i,//部件
                    ExpectedFunction = "预期功能" + i,//预期功能
                    Malfunction = "故障" + i,//故障
                    Risk = "风险" + i,//风险
                    HazardousFactor = "危害因素" + i,//危害因素
                    ControlRequirement = "控制要求" + i,//控制要求
                    FXTypeID = FX_FXTypeList[new Random().Next(0, 9)].Id,
                    RiskLevel = gradeLev3guid,//风险等级
                });
            }

            //风险_工艺介质
            for (int i = 0; i < 20; i++)
            {
                context.Set<FX_Process>().Add(new FX_Process()
                {

                    FeatureCharacteristics = "要素特性" + i,//要素特性
                    GuideWord = "引导词" + i,//引导词
                    Deviation = "偏差" + i,//偏差
                    FXTypeID = FX_FXTypeList[new Random().Next(0, 9)].Id,
                    RiskLevel = gradeLev3guid,//风险等级
                    Risk = "风险" + i,//风险
                    HazardousFactor = "危害因素" + i,//危害因素
                    ControlRequirement = "控制要求" + i//控制要求
                });
            }
            //风险_场所环境
            for (int i = 0; i < 20; i++)
            {
                context.Set<FX_Environment>().Add(new FX_Environment()
                {

                    PlaceEnvironmentName = "场所环境" + i,//场所环境
                    EnergySource = "能量源" + i,//能量源
                    FXTypeID = FX_FXTypeList[new Random().Next(0, 9)].Id,
                    RiskLevel = gradeLev3guid,//风险等级
                    Risk = "风险" + i,//风险
                    HazardousFactor = "危害因素" + i,//危害因素
                    ControlRequirement = "控制要求" + i//控制要求
                });
            }

            context.SaveChanges();
        }
    }
}
